package biz.obake.team.touchprotector.features.proximity;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import biz.obake.team.touchprotector.g.c;
import biz.obake.team.touchprotector.g.d;
import java.util.Map;

public class b extends biz.obake.team.touchprotector.d.b implements SensorEventListener {

    /* renamed from: d  reason: collision with root package name */
    private d f1664d = new d(this, 8, 2, "Proximity");
    private float e;
    private Handler f = new Handler();

    class a implements Runnable {
        a() {
        }

        public void run() {
            b.this.h();
        }
    }

    /* renamed from: biz.obake.team.touchprotector.features.proximity.b$b  reason: collision with other inner class name */
    private class C0075b {

        /* renamed from: a  reason: collision with root package name */
        boolean f1666a;

        /* renamed from: b  reason: collision with root package name */
        boolean f1667b;

        /* renamed from: c  reason: collision with root package name */
        boolean f1668c;

        /* renamed from: d  reason: collision with root package name */
        boolean f1669d;
        /* access modifiers changed from: private */
        public boolean e;
        boolean f;
        boolean g;
        boolean h;
        boolean i;
        boolean j;

        private C0075b(b bVar) {
            this.f1666a = biz.obake.team.touchprotector.d.i.b.c();
            this.f1667b = !c.b("Sensors.Paused");
            this.f1668c = "Locked".equals(c.c("TPService.State"));
            this.f1669d = "Unlocked".equals(c.c("TPService.State"));
            this.e = "RequestChannel.Proximity".equals(c.c("TPService.LockedBy"));
            this.f = biz.obake.team.touchprotector.g.a.g("lock_proximity");
            this.g = biz.obake.team.touchprotector.g.a.g("unlock_proximity");
            this.h = biz.obake.team.touchprotector.g.a.g("unlock_proximity_uncovered");
            this.i = biz.obake.team.touchprotector.g.a.g("unlock_proximity_uncovered_force");
            this.j = c.b("Proximity.FalseTesting");
        }

        /* synthetic */ C0075b(b bVar, a aVar) {
            this(bVar);
        }
    }

    public static void d(Map<String, String> map) {
        map.put("Proximity.State", "Off");
        map.put("Proximity.PreState", "Off");
    }

    public static boolean e() {
        return ((SensorManager) biz.obake.team.android.a.a().getSystemService("sensor")).getDefaultSensor(8) != null;
    }

    private String f(SensorEvent sensorEvent) {
        float f2 = sensorEvent.values[0];
        String l = biz.obake.team.touchprotector.g.a.l("proximity_distance");
        return f2 <= ("auto".equals(l) ? this.e : Float.parseFloat(l)) ? "Covered" : "Uncovered";
    }

    private void g() {
        if (!this.f1664d.g()) {
            this.f1664d.h();
            this.e = this.f1664d.f().getMaximumRange() / 2.0f;
        }
    }

    /* access modifiers changed from: private */
    public void h() {
        C0075b bVar = new C0075b(this, (a) null);
        boolean z = true;
        boolean z2 = bVar.f1666a && bVar.f1667b && bVar.f1669d && bVar.f;
        boolean z3 = bVar.f1666a && bVar.f1667b && bVar.f1668c && bVar.g;
        boolean z4 = bVar.f1666a && bVar.f1667b && bVar.f1668c && bVar.e && bVar.h;
        boolean z5 = bVar.f1666a && bVar.f1667b && bVar.f1668c && bVar.i;
        if (!bVar.f1666a || !bVar.f1667b || !bVar.f1668c || !bVar.j) {
            z = false;
        }
        if (z2 || z3 || z4 || z5 || z) {
            g();
        } else {
            i();
        }
    }

    private void i() {
        if (this.f1664d.g()) {
            this.f1664d.j();
            c.g("Proximity.PreState", c.c("Proximity.State"));
            c.g("Proximity.State", "Off");
        }
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Can't fix incorrect switch cases order */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void b(java.lang.String r2) {
        /*
            r1 = this;
            int r0 = r2.hashCode()
            switch(r0) {
                case -2066548004: goto L_0x004e;
                case -2013965124: goto L_0x0044;
                case -1898571506: goto L_0x003a;
                case -1767396190: goto L_0x0030;
                case 665331012: goto L_0x0026;
                case 831789315: goto L_0x001c;
                case 1690883215: goto L_0x0012;
                case 1941313131: goto L_0x0008;
                default: goto L_0x0007;
            }
        L_0x0007:
            goto L_0x0058
        L_0x0008:
            java.lang.String r0 = "lock_proximity"
            boolean r2 = r2.equals(r0)
            if (r2 == 0) goto L_0x0058
            r2 = 3
            goto L_0x0059
        L_0x0012:
            java.lang.String r0 = "Screen.State"
            boolean r2 = r2.equals(r0)
            if (r2 == 0) goto L_0x0058
            r2 = 0
            goto L_0x0059
        L_0x001c:
            java.lang.String r0 = "Sensors.Paused"
            boolean r2 = r2.equals(r0)
            if (r2 == 0) goto L_0x0058
            r2 = 1
            goto L_0x0059
        L_0x0026:
            java.lang.String r0 = "unlock_proximity"
            boolean r2 = r2.equals(r0)
            if (r2 == 0) goto L_0x0058
            r2 = 4
            goto L_0x0059
        L_0x0030:
            java.lang.String r0 = "unlock_proximity_uncovered"
            boolean r2 = r2.equals(r0)
            if (r2 == 0) goto L_0x0058
            r2 = 5
            goto L_0x0059
        L_0x003a:
            java.lang.String r0 = "unlock_proximity_uncovered_force"
            boolean r2 = r2.equals(r0)
            if (r2 == 0) goto L_0x0058
            r2 = 6
            goto L_0x0059
        L_0x0044:
            java.lang.String r0 = "Proximity.FalseTesting"
            boolean r2 = r2.equals(r0)
            if (r2 == 0) goto L_0x0058
            r2 = 7
            goto L_0x0059
        L_0x004e:
            java.lang.String r0 = "TPService.State"
            boolean r2 = r2.equals(r0)
            if (r2 == 0) goto L_0x0058
            r2 = 2
            goto L_0x0059
        L_0x0058:
            r2 = -1
        L_0x0059:
            switch(r2) {
                case 0: goto L_0x005d;
                case 1: goto L_0x005d;
                case 2: goto L_0x005d;
                case 3: goto L_0x005d;
                case 4: goto L_0x005d;
                case 5: goto L_0x005d;
                case 6: goto L_0x005d;
                case 7: goto L_0x005d;
                default: goto L_0x005c;
            }
        L_0x005c:
            goto L_0x006d
        L_0x005d:
            android.os.Handler r2 = r1.f
            r0 = 0
            r2.removeCallbacksAndMessages(r0)
            android.os.Handler r2 = r1.f
            biz.obake.team.touchprotector.features.proximity.b$a r0 = new biz.obake.team.touchprotector.features.proximity.b$a
            r0.<init>()
            r2.post(r0)
        L_0x006d:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.features.proximity.b.b(java.lang.String):void");
    }

    public void onAccuracyChanged(Sensor sensor, int i) {
    }

    public void onSensorChanged(SensorEvent sensorEvent) {
        String f2 = f(sensorEvent);
        if (!f2.equals(c.c("Proximity.State"))) {
            biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
            b2.d("Proximity: " + f2);
            c.g("Proximity.PreState", c.c("Proximity.State"));
            c.g("Proximity.State", f2);
        }
    }

    public void start() {
        if (e()) {
            super.start();
            h();
        }
    }

    public void stop() {
        if (e()) {
            super.stop();
            i();
        }
    }
}
